/**
 * \* Created with IntelliJ IDEA.
 * \* User: chenhao
 * \* Date: 2022/3/8
 * \* Time: 19:20
 * \* Description:
 * \
 */

import java.util.concurrent.locks.ReentrantLock;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: chenhao
 * \* Date: 2022/3/7
 * \* Time: 19:22
 * \* Description:
 * \
 */
public class demo2 {

    static  int a=1;




    public static void test1(){
        ReentrantLock lock =new ReentrantLock(true);
        try {
            lock.lock(); //加锁
            for (int i = 0; i < 100; i++) {
                a++;
            }
            System.out.println(a);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock(); //解锁
        }




    }
    public static void main(String[] args) {
        test1();
    }
}